<!--
  #%L
  thinkbig-ui-feed-manager
  %%
  Copyright (C) 2017 ThinkBig Analytics
  %%
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  #L%
  -->
<md-dialog aria-label="Validation Results" ng-cloak>
    <ng-form name="policyForm">
        <div  class="md-toolbar-tools">
            <h4 class="md-title"><span>{{title}} {{"views.define-feed-data-processing-field-policy-dialog.ff" | translate}} {{field.name}}</span></h4>
            <span flex></span>
        </div>
        <md-dialog-content layout="column" style="min-width:500px;padding-top:0px;" layout-padding>

            <div ng-if="policyRules != null && policyRules.length >0 ">
                <span class="hint">{{"views.define-feed-data-processing-field-policy-dialog.Dpuadtr" | translate}}</span>

                <ul dnd-list="policyRules" class="simple-dnd-list">
                    <li ng-repeat="rule in policyRules"
                        dnd-draggable="rule"
                        dnd-moved="onMovedPolicyRule($index)"
                        dnd-effect-allowed="move">
                        <div layout="row" layout-align="start">
                            <div layout="column" flex>
                                <span class="md-list-item-text">{{$index+1}}. {{rule.name}}</span>
                                <span class="md-list-item-text hint">{{rule.type}}</span>
                            </div>
                            <div layout="row">
                                <md-button class="md-icon-button" ng-click="editPolicy($event,$index,rule)">
                                    <ng-md-icon icon="edit" style="fill:grey"></ng-md-icon>
                                </md-button>
                                  <md-button class="md-icon-button" ng-click="deletePolicyByIndex($index)">
                                      <ng-md-icon icon="delete" style="fill:grey" ></ng-md-icon>
                                  </md-button>
                            </div>
                        </div>
                    </li>

                </ul>


<!--
                <md-list>
                    <md-list-item ng-repeat="rule in policyRules track by $index">
                        <div layout="column">
                            <span class="md-list-item-text">{{$index+1}}. {{rule.name}}</span>
                            <span class="md-list-item-text hint">{{rule.type}}</span>
                        </div>
                        <span class="md-secondary">
                            <md-button class="md-icon-button" ng-click="editPolicy($event,$index,rule)">
                                <ng-md-icon icon="edit" ></ng-md-icon>
                            </md-button>
                              <md-button class="md-icon-button" ng-click="deletePolicyByIndex($index)">
                                  <ng-md-icon icon="delete" ></ng-md-icon>
                              </md-button>
                        </span>

                        <md-divider></md-divider>
                    </md-list-item>
                </md-list>
                -->
            </div>

            <div class="edit-form" >
                 <md-progress-linear md-mode="indeterminate" ng-if="loadingPolicies"></md-progress-linear>

                <div class="md-title">{{titleText}}</div>

                <md-radio-group ng-model="selectedOptionType" layout="row" ng-if="optionTypes != null" class="layout-padding-top">
                    <md-radio-button aria-label="Select option type" ng-repeat="optionType in optionTypes"
                                     ng-value="optionType.type"
                                     aria-label="{{optionType.name}}"
                                     ng-click="onChangedOptionType(optionType.type)">
                        {{optionType.name}}
                    </md-radio-button>
                </md-radio-group>


                <md-input-container class="md-block layout-padding-top-bottom" style="margin-top:0px;">
                    <label class="md-container-ignore label-small layout-padding-top">{{"views.define-feed-data-processing-field-policy-dialog.SRT" | translate}}</label>
                    <md-select ng-model="ruleType" ng-model-options="{trackBy: '$value.name'}" ng-change="onRuleTypeChange()" aria-label="Rule Type">
                        <md-option ng-value="opt" ng-repeat="opt in options">{{ opt.name }}</md-option>
                    </md-select>
                    <span class="hint">{{editRule.description}}</span>
                </md-input-container>
                <thinkbig-policy-input-form the-form="policyForm" rule="editRule" mode="ruleMode" feed="feed"></thinkbig-policy-input-form>

                <div layout="row" layout-align="start stretch" flex>
                    <md-button ng-if="editRule != null" ng-click="cancelEdit($event)">{{cancelText}}</md-button>
                    <span flex></span>
                    <md-button class="md-primary" ng-if="editRule != null" ng-click="addPolicy($event)" ng-disabled="policyForm.$invalid">{{addText}}</md-button>
                </div>
            </div>

        </md-dialog-content>
        <md-dialog-actions layout="row" layout-align="start stretch" flex>
            <span flex></span>
            <md-button ng-click="cancel($event)">
                {{"views.define-feed-data-processing-field-policy-dialog.Cancel" | translate}}
            </md-button>
            <md-button class="md-raised md-primary" ng-click="done($event)" ng-disabled="!pendingEdits || editRule != null || policyForm.$invalid">
                {{"views.define-feed-data-processing-field-policy-dialog.Done" | translate}}
            </md-button>
        </md-dialog-actions>
    </ng-form>
</md-dialog>

